package com.tianji.contract.bill.task;

import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
public class BillConsumerStarter {

    private final BillConsumer billConsumer;

    public BillConsumerStarter(BillConsumer billConsumer) {
        this.billConsumer = billConsumer;
    }

    @Bean
    public ApplicationRunner startConsumerThread() {
        return args -> {
            Thread consumerThread = new Thread(billConsumer);
            consumerThread.setDaemon(true); // 设置为守护线程
            consumerThread.start();
            System.out.println("消费者线程已启动...");
        };
    }
}
